<?php
class DateTimeUtils {
	
	public static $DAY_INTERVAL = 'DAY';
	public static $HOUR_INTERVAL = 'HOUR';
	public static $MINUTE_INTERVAL = 'MINUTE';
	
	/**
	 * Tinh khoang cach giua dang 2 ngay voi dinh dang dd/mm/yyyy
	 * Enter description here ...
	 * @param $fromDate
	 * @param $toDate
	 * @param khoang cach tinh theo don vi ngay, thang, nam
	 */
	static function intervalDate($fromDate, $toDate, $outputType) {
		$arrFromDate = explode ( '/', $fromDate );
		$arrToDate = explode ( '/', $toDate );
		$iFromDate = mktime ( 0, 0, 0, $arrFromDate [1], $arrFromDate [0], $arrFromDate [2] );
		$iToDate = mktime ( 0, 0, 0, $arrToDate [1], $arrToDate [0], $arrToDate [2] );
		
		$m_int = abs ( $iFromDate - $iToDate );
		switch ($outputType) {
			case DateTimeUtils::$DAY_INTERVAL :
				$m_int /= 86400;
				break;
			case DateTimeUtils::$HOUR_INTERVAL :
				$m_int /= 3600;
				break;
			case DateTimeUtils::$MINUTE_INTERVAL :
				$m_int /= 60;
				break;
			default :
				break;
		}
		return $m_int;
	}
}
?>